public class Test3 {
    public static void main(String[] args) {
        Person person1 = new Person("张三",18);
        Person person2 = new Person("张三",18);

        System.out.println(person1.equals(person2));

    }
}
class Person {
    public String name;
    public int age;
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (this == obj) {
           return true;
        }
        if (!(obj instanceof Person)) {
            return false;
        }

        Person per = (Person)obj;
        if (this.name == per.name && this.age == ((Person)obj).age) {
            return true;
        }
        return false;
    }
}



